from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-27 14:02:37.110110
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 27, Nov, 2022
Time: 14:02:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0700
Nobs: 853.000 HQIC: -51.3792
Log likelihood: 11191.9 FPE: 4.00849e-23
AIC: -51.5711 Det(Omega_mle): 3.60932e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298973 0.050264 5.948 0.000
L1.Burgenland 0.109681 0.034552 3.174 0.002
L1.Kärnten -0.106020 0.018403 -5.761 0.000
L1.Niederösterreich 0.210630 0.072227 2.916 0.004
L1.Oberösterreich 0.100378 0.068605 1.463 0.143
L1.Salzburg 0.251632 0.036632 6.869 0.000
L1.Steiermark 0.037130 0.048029 0.773 0.439
L1.Tirol 0.107362 0.038929 2.758 0.006
L1.Vorarlberg -0.059879 0.033558 -1.784 0.074
L1.Wien 0.054391 0.061347 0.887 0.375
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067657 0.103669 0.653 0.514
L1.Burgenland -0.030139 0.071263 -0.423 0.672
L1.Kärnten 0.047570 0.037957 1.253 0.210
L1.Niederösterreich -0.172188 0.148968 -1.156 0.248
L1.Oberösterreich 0.376450 0.141499 2.660 0.008
L1.Salzburg 0.288603 0.075554 3.820 0.000
L1.Steiermark 0.108587 0.099061 1.096 0.273
L1.Tirol 0.316636 0.080291 3.944 0.000
L1.Vorarlberg 0.023072 0.069213 0.333 0.739
L1.Wien -0.019842 0.126529 -0.157 0.875
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197714 0.026031 7.595 0.000
L1.Burgenland 0.092542 0.017894 5.172 0.000
L1.Kärnten -0.008730 0.009531 -0.916 0.360
L1.Niederösterreich 0.268520 0.037405 7.179 0.000
L1.Oberösterreich 0.114674 0.035529 3.228 0.001
L1.Salzburg 0.052777 0.018971 2.782 0.005
L1.Steiermark 0.016748 0.024874 0.673 0.501
L1.Tirol 0.098499 0.020160 4.886 0.000
L1.Vorarlberg 0.056074 0.017379 3.227 0.001
L1.Wien 0.112215 0.031771 3.532 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105198 0.026705 3.939 0.000
L1.Burgenland 0.047318 0.018357 2.578 0.010
L1.Kärnten -0.017429 0.009777 -1.783 0.075
L1.Niederösterreich 0.196871 0.038374 5.130 0.000
L1.Oberösterreich 0.279934 0.036450 7.680 0.000
L1.Salzburg 0.120229 0.019462 6.178 0.000
L1.Steiermark 0.101537 0.025518 3.979 0.000
L1.Tirol 0.123922 0.020683 5.992 0.000
L1.Vorarlberg 0.068795 0.017829 3.859 0.000
L1.Wien -0.027200 0.032593 -0.835 0.404
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130344 0.048314 2.698 0.007
L1.Burgenland -0.049473 0.033212 -1.490 0.136
L1.Kärnten -0.039365 0.017689 -2.225 0.026
L1.Niederösterreich 0.167271 0.069425 2.409 0.016
L1.Oberösterreich 0.140441 0.065944 2.130 0.033
L1.Salzburg 0.284998 0.035211 8.094 0.000
L1.Steiermark 0.032291 0.046167 0.699 0.484
L1.Tirol 0.162854 0.037419 4.352 0.000
L1.Vorarlberg 0.103812 0.032256 3.218 0.001
L1.Wien 0.068479 0.058968 1.161 0.246
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058515 0.038268 1.529 0.126
L1.Burgenland 0.042566 0.026306 1.618 0.106
L1.Kärnten 0.049866 0.014011 3.559 0.000
L1.Niederösterreich 0.227813 0.054989 4.143 0.000
L1.Oberösterreich 0.271593 0.052232 5.200 0.000
L1.Salzburg 0.058118 0.027889 2.084 0.037
L1.Steiermark -0.006933 0.036567 -0.190 0.850
L1.Tirol 0.156118 0.029638 5.268 0.000
L1.Vorarlberg 0.068505 0.025549 2.681 0.007
L1.Wien 0.074427 0.046706 1.594 0.111
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185432 0.045813 4.048 0.000
L1.Burgenland -0.004508 0.031492 -0.143 0.886
L1.Kärnten -0.060871 0.016773 -3.629 0.000
L1.Niederösterreich -0.086638 0.065831 -1.316 0.188
L1.Oberösterreich 0.191874 0.062530 3.069 0.002
L1.Salzburg 0.059693 0.033388 1.788 0.074
L1.Steiermark 0.225768 0.043776 5.157 0.000
L1.Tirol 0.494834 0.035481 13.946 0.000
L1.Vorarlberg 0.047826 0.030586 1.564 0.118
L1.Wien -0.051379 0.055915 -0.919 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158473 0.052187 3.037 0.002
L1.Burgenland -0.009065 0.035874 -0.253 0.801
L1.Kärnten 0.064858 0.019107 3.394 0.001
L1.Niederösterreich 0.203049 0.074991 2.708 0.007
L1.Oberösterreich -0.067726 0.071231 -0.951 0.342
L1.Salzburg 0.222373 0.038034 5.847 0.000
L1.Steiermark 0.113657 0.049868 2.279 0.023
L1.Tirol 0.084019 0.040419 2.079 0.038
L1.Vorarlberg 0.122360 0.034842 3.512 0.000
L1.Wien 0.109846 0.063695 1.725 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356737 0.030774 11.592 0.000
L1.Burgenland 0.008754 0.021154 0.414 0.679
L1.Kärnten -0.024656 0.011267 -2.188 0.029
L1.Niederösterreich 0.228513 0.044221 5.168 0.000
L1.Oberösterreich 0.157186 0.042004 3.742 0.000
L1.Salzburg 0.053103 0.022428 2.368 0.018
L1.Steiermark -0.018331 0.029406 -0.623 0.533
L1.Tirol 0.117642 0.023834 4.936 0.000
L1.Vorarlberg 0.071997 0.020546 3.504 0.000
L1.Wien 0.050422 0.037560 1.342 0.179
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043790 0.161070 0.191938 0.165653 0.132174 0.124459 0.070199 0.231313
Kärnten 0.043790 1.000000 0.002263 0.131829 0.044991 0.099210 0.427410 -0.050615 0.102081
Niederösterreich 0.161070 0.002263 1.000000 0.345087 0.166536 0.310798 0.128217 0.192183 0.341058
Oberösterreich 0.191938 0.131829 0.345087 1.000000 0.235431 0.339971 0.177357 0.179543 0.275085
Salzburg 0.165653 0.044991 0.166536 0.235431 1.000000 0.153246 0.145274 0.152880 0.140363
Steiermark 0.132174 0.099210 0.310798 0.339971 0.153246 1.000000 0.163242 0.148407 0.092766
Tirol 0.124459 0.427410 0.128217 0.177357 0.145274 0.163242 1.000000 0.122216 0.164128
Vorarlberg 0.070199 -0.050615 0.192183 0.179543 0.152880 0.148407 0.122216 1.000000 0.019973
Wien 0.231313 0.102081 0.341058 0.275085 0.140363 0.092766 0.164128 0.019973 1.000000